//
// Created by admin on 2021/2/15.
//

#include "RenderItemStaticOpaque.h"
#include "RenderItem.h"
#include "Buffer.h"
#include "GLESUtils.h"
#include "Model.h"
#include "DummyModel.h"
#include "MeshModel.h"
#include "SkinnedMeshModel.h"
#include "Texture.h"
#include "Scene.h"
#include "Camera.h"
#include <gles3/gl32.h>
#include <ext.hpp>


RenderItemStaticOpaque<GraphicsAPI::GLESv3>::RenderItemStaticOpaque() : RenderItemOpaque<GraphicsAPI::GLESv3>()
{
    with_skinned_mesh_anim = false;
}

void RenderItemStaticOpaque<GraphicsAPI::GLESv3>::LoadMeshFileData(const char * mesh_file, glm::vec3 translation, glm::vec3 rotation, glm::vec3 scale)
{
    auto attrib_type_list = std::unordered_set<VertexAttribType> {
            VertexAttribType::POSITION_F3,
            VertexAttribType::NORMAL_F3,
            VertexAttribType::UV1_F2,
    };

    model = std::make_shared<MeshModel>(mesh_file, attrib_type_list);
    model->SetScale(scale);
    model->SetRotation(rotation);
    model->SetTranslation(translation);

    AppendVertexAttribData(
            VertexAttribType::POSITION_F3,
            model->GetVertexData(VertexAttribType::POSITION_F3),
            model->GetVertexDataLength(VertexAttribType::POSITION_F3),
            0, 0);

    AppendVertexAttribData(
            VertexAttribType::NORMAL_F3,
            model->GetVertexData(VertexAttribType::NORMAL_F3),
            model->GetVertexDataLength(VertexAttribType::NORMAL_F3),
            0, 0);

    AppendVertexAttribData(
            VertexAttribType::UV1_F2,
            model->GetVertexData(VertexAttribType::UV1_F2),
            model->GetVertexDataLength(VertexAttribType::UV1_F2),
            0, 0);

    vertexNumber = model->GetVertexNumber();
    faceNumber = model->GetFaceNumber();
    SetElementData(model->GetIndexData(), model->GetIndexDataLength());
}